package com.huilai.platform.country_platform.controller;

import com.huilai.platform.country_platform.core.Result;
import com.huilai.platform.country_platform.model.User;
import com.huilai.platform.country_platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 作者：洪霓
 * 日期：2023/3/12
 * 注释：
 */
@Controller
@RequestMapping("/user")
public class UserCenterController {
    @Autowired
    private UserService userService;

    @RequestMapping("/userCenterUI")
    public String userCenterUI(Model model, HttpServletRequest request) {
        List<String> educationList = new ArrayList<>();
        educationList.add("无");
        educationList.add("小学");
        educationList.add("初中");
        educationList.add("高中");
        educationList.add("本科");
        educationList.add("硕士");
        educationList.add("博士及以上");

        List<String> politicalList = new ArrayList<>();
        politicalList.add("中国共产党党员");
        politicalList.add("中共预备党员");
        politicalList.add("共青团员");
        politicalList.add("民主党派人士");
        politicalList.add("无党派民主人士");
        politicalList.add("群众");

        List<String> townList = new ArrayList<>();
        townList.add("仙庵镇");

        List<String> villageList = new ArrayList<>();
        villageList.add("仙庵村");
        villageList.add("锡溪村");
        villageList.add("宁寨村");
        villageList.add("顶溪村");
        villageList.add("东埔村");
        villageList.add("四美村");
        villageList.add("京陇村");
        villageList.add("点铺村");
        villageList.add("田墘村");
        villageList.add("里行村");
        villageList.add("华园村");
        User user = userService.getUserByCookie(request);
        model.addAttribute("user", user);
        model.addAttribute("politicalList",politicalList);
        model.addAttribute("educationList",educationList);
        model.addAttribute("townList",townList);
        model.addAttribute("villageList",villageList);
        return "user/user-center";
    }

    @PostMapping("/updateUserPassword")
    @ResponseBody
    public Result updateUserPassword(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam("id") Integer id, @RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword){
        Result result = userService.updateUserPassword(session, request, response, id, oldPassword, newPassword);
        return result;
    }


}
